/******************************************************************************
*  Filename:       rf_patch_rfe_ble_coex.h
*
*  Description: RF core patch for coexistence support for Bluetooth 5 in CC13x2 and CC26x2.
*
*  Copyright (c) 2015-2020, Texas Instruments Incorporated
*  All rights reserved.
*
*  Redistribution and use in source and binary forms, with or without
*  modification, are permitted provided that the following conditions are met:
*
*  1) Redistributions of source code must retain the above copyright notice,
*     this list of conditions and the following disclaimer.
*
*  2) Redistributions in binary form must reproduce the above copyright notice,
*     this list of conditions and the following disclaimer in the documentation
*     and/or other materials provided with the distribution.
*
*  3) Neither the name of the ORGANIZATION nor the names of its contributors may
*     be used to endorse or promote products derived from this software without
*     specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
*  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
*  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
*  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
*  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
*  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
*  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
*  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
*  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
*  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
*  POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/


#include <stdint.h>
#include "rf_patch_rfe_ble_coex.h"
#include <ti/devices/DeviceFamily.h>
#include DeviceFamily_constructPath(inc/hw_types.h)

#ifndef RFE_PATCH_TYPE
#define RFE_PATCH_TYPE static const uint32_t
#endif

#ifndef PATCH_FUN_SPEC
#define PATCH_FUN_SPEC
#endif

#ifndef RFC_RFERAM_BASE
#define RFC_RFERAM_BASE 0x2100C000
#endif

#ifndef RFE_PATCH_MODE
#define RFE_PATCH_MODE 0
#endif

RFE_PATCH_TYPE patchBleCoexRfe[510] = {
   0x35f86145,
   0xa24675f9,
   0x1f40a357,
   0x34f11307,
   0x40004030,
   0x40034001,
   0x400f4007,
   0x40cf404f,
   0x43cf41cf,
   0x4fcf47cf,
   0x2fcf3fcf,
   0x0fcf1fcf,
   0x40004030,
   0x40034001,
   0x400f4007,
   0x40cf404f,
   0x6fcf7fcf,
   0x4fcf5fcf,
   0x2fcf3fcf,
   0x0fcf1fcf,
   0x9100c050,
   0xc0707000,
   0x70009100,
   0x00213182,
   0xb1109131,
   0x81017000,
   0xa100b101,
   0x91323182,
   0x9101b110,
   0x81411011,
   0x403b2241,
   0x700006f1,
   0x9150c050,
   0xc0707000,
   0x70009150,
   0x00213182,
   0xb1609181,
   0x10257000,
   0x9100c050,
   0xc080c3f4,
   0x6f031420,
   0x04411031,
   0x22f082a0,
   0x26514058,
   0x3182c022,
   0x91310021,
   0x3963b110,
   0x04411031,
   0x3182c082,
   0x91310021,
   0x3963b110,
   0xc0a21031,
   0x00213182,
   0xb1109131,
   0x31151050,
   0x92551405,
   0x642b7000,
   0x1031c2b2,
   0x31610631,
   0x642e02c1,
   0x1031c112,
   0x06713921,
   0x02e13151,
   0x7000642e,
   0x82b16428,
   0x39813181,
   0x642ec0e2,
   0xc111642b,
   0x642ec122,
   0x688bc470,
   0xc0c2c111,
   0x64a4642e,
   0x700064b7,
   0x82b16440,
   0x39813181,
   0x6446c182,
   0xc1116443,
   0x6446c0a2,
   0x689dc470,
   0xc162c331,
   0x64a46446,
   0x700064b7,
   0xb054b050,
   0x80407100,
   0x44b12240,
   0x40a42200,
   0x8081b060,
   0x44a41e11,
   0xa0547000,
   0x80f0b064,
   0x40a42200,
   0x12407000,
   0xb03290b0,
   0x395382a3,
   0x64713953,
   0x68bfc2f0,
   0xc1f18080,
   0xc1510410,
   0x40cb1c10,
   0xc221642b,
   0x642ec0c2,
   0x644360cf,
   0xc162c441,
   0xce306446,
   0x128068d0,
   0xb03290b0,
   0x642b7000,
   0xc0c2c201,
   0x80a0642e,
   0x39403180,
   0xc10168dc,
   0x642ec0c2,
   0xc122c101,
   0x82a3642e,
   0x12c06471,
   0xb03290b0,
   0x64437000,
   0xc162c401,
   0x80a06446,
   0x39403180,
   0xc30168f0,
   0x6446c162,
   0xc0a2c101,
   0x82a36446,
   0x12c06471,
   0xb03290b0,
   0x642b7000,
   0xc081c272,
   0xc122642e,
   0x642ec111,
   0xc111c002,
   0xc062642e,
   0x642ec331,
   0xc111c362,
   0xc302642e,
   0x642ec111,
   0x395382a3,
   0xc3e26471,
   0x22116433,
   0xc2424113,
   0x642ec881,
   0xc111c252,
   0xc272642e,
   0x642ecee1,
   0xc881c202,
   0xc202642e,
   0x642ec801,
   0x6927c170,
   0x642b7000,
   0xc801c242,
   0xc252642e,
   0x642ec011,
   0xc0e1c272,
   0xc002642e,
   0x642ec101,
   0xc301c062,
   0xc122642e,
   0x642ec101,
   0xc101c362,
   0xc302642e,
   0x642ec101,
   0x647182a3,
   0x73067000,
   0x720b7205,
   0xb050720e,
   0x80817100,
   0xa050b060,
   0xeff08092,
   0x93529341,
   0x224167f5,
   0x80804569,
   0x0410c1f1,
   0x11011630,
   0x6c011401,
   0x618a618a,
   0x618a618a,
   0x618a618a,
   0x6191618d,
   0x619b6197,
   0x62b5618a,
   0xc0f062b8,
   0x31320402,
   0x14122a41,
   0x11011632,
   0x6c011421,
   0x618b61a9,
   0x618f61a9,
   0x61936199,
   0x618a618a,
   0x619d62d6,
   0x618f62d6,
   0x6193619f,
   0x618a618a,
   0x618b61af,
   0x618f61af,
   0x61936199,
   0x618a618a,
   0x65c061a2,
   0x648061a2,
   0x648061a2,
   0x64d567cd,
   0x649261a2,
   0x64e967cd,
   0x64fd61a2,
   0x64fd61a2,
   0x652965c0,
   0x66e061a2,
   0x64fd61a2,
   0x619b66e0,
   0x61a5b0b0,
   0x7306b0b1,
   0xb0307205,
   0x78106149,
   0x7832c451,
   0xc5247853,
   0x782061b4,
   0x7842c451,
   0xc4c47853,
   0x926091a4,
   0x92829271,
   0xc0159293,
   0xc3f09245,
   0xc0f092b0,
   0x61a290a0,
   0x66b1b0e3,
   0x80f0a054,
   0x45ca2250,
   0x22008040,
   0x61c246a9,
   0xc800a0e3,
   0x81a991b0,
   0x8091b050,
   0x46842241,
   0x12f18262,
   0x102f0412,
   0x142f311f,
   0x22d68266,
   0xc08045dd,
   0xc18061de,
   0x6f0d1420,
   0x10de396d,
   0x044ec3f4,
   0x3182c082,
   0x396d002e,
   0x3182c0a2,
   0x826a002d,
   0x06fa398a,
   0x31808270,
   0xc00b3980,
   0x10bc180b,
   0x825318ac,
   0x149b1439,
   0x06f08260,
   0x31101001,
   0x81a11410,
   0x140c1410,
   0x39408280,
   0x100206f0,
   0x3001c011,
   0x1801c010,
   0x31821802,
   0x26c10021,
   0x22c691e1,
   0xb0034642,
   0xb063b013,
   0x8041b053,
   0x46a92201,
   0x92148204,
   0x1cb58225,
   0x18954e21,
   0x80f091b5,
   0x42132210,
   0x913d6284,
   0x913eb110,
   0x80e0b110,
   0x462b2200,
   0x422b22e6,
   0x1895b0e0,
   0x925f91b5,
   0x14f981a9,
   0x225080f0,
   0x221041c0,
   0x62bb4684,
   0x81a966b1,
   0x14598255,
   0x7100c0f0,
   0x6a3bb063,
   0x421322c6,
   0x625aa0e0,
   0x39808280,
   0x100206f0,
   0x3001c011,
   0x1801c010,
   0x31821802,
   0x26c10021,
   0x828791d1,
   0x39873947,
   0xb013b003,
   0xb053b063,
   0xb0637100,
   0xb012b002,
   0x22018041,
   0x81f446a9,
   0x82259214,
   0x4e681cb5,
   0x91b51895,
   0x221080f0,
   0x6284425a,
   0x92148204,
   0x18458224,
   0x4e721c75,
   0x221080f0,
   0x6284425a,
   0xb110913d,
   0x220080e0,
   0x22e6467a,
   0xb0e0427a,
   0x925f91b5,
   0x14f981a9,
   0x225080f0,
   0x221041c0,
   0x62bb4684,
   0x8280b063,
   0x100206f0,
   0x3001c011,
   0x1801c010,
   0x31821802,
   0x26c10021,
   0xb01391e1,
   0xb063b003,
   0xb064b053,
   0x7100b054,
   0x22018041,
   0xb06346a9,
   0x80f0b064,
   0x41c02250,
   0x46972240,
   0x92118201,
   0x18918221,
   0xb03191b1,
   0xa0e36297,
   0x8251a0e0,
   0x318281b2,
   0xa0033d82,
   0x82627000,
   0x06f23942,
   0x80a2604b,
   0x61a2644b,
   0x7100b050,
   0x829061a2,
   0x22018041,
   0x820446a9,
   0x82259214,
   0x91b51895,
   0x221180f1,
   0x6abc4684,
   0x22018041,
   0x820446a9,
   0x82259214,
   0x4a361cc5,
   0x91b51895,
   0x221080f0,
   0x628442c8,
   0x91e07860,
   0x9250c2d0,
   0x7870c4c4,
   0xc132c2e1,
   0x61b4cb03,
   0xb0e3a0e2,
   0x80f0a054,
   0x46ea2250,
   0x22008040,
   0x62e247c6,
   0xa040a0e3,
   0x8260827d,
   0x0410c0f1,
   0x826a1009,
   0x041a394a,
   0x39808260,
   0x100e0410,
   0x10bc10ab,
   0x644b10c2,
   0xb003b013,
   0xb053677a,
   0xb054b050,
   0xb013b064,
   0x6763675a,
   0x80417100,
   0x47c62201,
   0x221080f0,
   0x22f04716,
   0xb06447b3,
   0x43062231,
   0x6780b063,
   0x63066733,
   0x81bfb064,
   0x3d8f318f,
   0x80417100,
   0x47c62201,
   0x80f0b064,
   0x432c2250,
   0x8261b063,
   0x472722c1,
   0x82616780,
   0x471a22d1,
   0x631a6733,
   0x81c281b1,
   0x3d813181,
   0x3d823182,
   0x820062e0,
   0x82239210,
   0x4f4018d3,
   0x16130bf3,
   0x4b591ce3,
   0x82339213,
   0x6345143b,
   0x4b591ce3,
   0x82339213,
   0x1cab183b,
   0x1c9b4f55,
   0x1cbc4b57,
   0x10b24359,
   0x22d08260,
   0x80f04352,
   0x47592210,
   0x675a644b,
   0x10ab6359,
   0x109b6349,
   0x70006349,
   0xc0f18280,
   0xb0630410,
   0x6b5d7100,
   0xb0e010bc,
   0x82027000,
   0x82229212,
   0x18128251,
   0x181281a1,
   0x31818291,
   0x1c123d81,
   0xb0e24b71,
   0xc7f1b032,
   0x4f751421,
   0x91b2c812,
   0xb03191c2,
   0x7000b0e1,
   0xc0061208,
   0x91b0c800,
   0x700091c0,
   0x82008251,
   0x82209210,
   0x81a11810,
   0x14061810,
   0x829280e1,
   0x3d823182,
   0x4b921c20,
   0x2221b0e2,
   0xb0324796,
   0x43962221,
   0xb032a0e2,
   0x39418281,
   0x0401c0f0,
   0x43a41e01,
   0xc0101618,
   0x1c083010,
   0x106047b2,
   0x10063c10,
   0x1461c7f1,
   0xc8164fa8,
   0x81c191b6,
   0x3d813181,
   0x4baf1c16,
   0xb03191c6,
   0x1208c006,
   0xa0037000,
   0xb064b063,
   0x6529b0ef,
   0x80407100,
   0x47c62200,
   0x64fdb064,
   0x7100a0ef,
   0x22008040,
   0xb06447c6,
   0x6306b003,
   0x8251a0e3,
   0x318281b2,
   0xa0033d82,
   0x642b7000,
   0xb05fb06f,
   0x1e118081,
   0xb05043ee,
   0x7100b054,
   0x22f08040,
   0xb06f43e6,
   0x22f282b2,
   0xc40143e6,
   0x6446c162,
   0xc0c2c201,
   0xa05f642e,
   0x63eeb06f,
   0x22408040,
   0xa05443f1,
   0x80f1b064,
   0x47d32201,
   0xb06fa05f,
   0x22007000,
   0xb06043d3,
   0x933063d0,
   0x22008320,
   0xb31047f6,
   0x00007000
};

PATCH_FUN_SPEC void rf_patch_rfe_ble_coex(void)
{
#ifdef __PATCH_NO_UNROLLING
   uint32_t i;
   for (i = 0; i < 510; i++) {
      HWREG(RFC_RFERAM_BASE + 4 * i) = patchBleCoexRfe[i];
   }
#else
   const uint32_t *pS = patchBleCoexRfe;
   volatile unsigned long *pD = &HWREG(RFC_RFERAM_BASE);
   uint32_t t1, t2, t3, t4, t5, t6, t7, t8;
   uint32_t nIterations = 63;

   do {
      t1 = *pS++;
      t2 = *pS++;
      t3 = *pS++;
      t4 = *pS++;
      t5 = *pS++;
      t6 = *pS++;
      t7 = *pS++;
      t8 = *pS++;
      *pD++ = t1;
      *pD++ = t2;
      *pD++ = t3;
      *pD++ = t4;
      *pD++ = t5;
      *pD++ = t6;
      *pD++ = t7;
      *pD++ = t8;
   } while (--nIterations);

   t1 = *pS++;
   t2 = *pS++;
   t3 = *pS++;
   t4 = *pS++;
   t5 = *pS++;
   t6 = *pS++;
   *pD++ = t1;
   *pD++ = t2;
   *pD++ = t3;
   *pD++ = t4;
   *pD++ = t5;
   *pD++ = t6;
#endif
}
